<template>
  <div>
    <!-- $emit $on进行同组件传值 -->
    <h1>first</h1>
    <!-- 可以添加多个事件，$on可以监听多个事件 也可以同时传递多个参数 -->
    <input type="text" v-model="msg" @change="getMsg(1)" />
    <button @click="sum(1,2)">test emit on</button>
  </div>
</template>

<script>
export default {
  name: "First",
  props: [""],
  data() {
    return {
      msg: ""
    };
  },

  components: {},

  computed: {},
  mounted() {
    //监听事件 添加回调函数
    this.$on("getInfo", (info, num) => {
      console.log(info);
      console.log(num);
    });

    this.$on("sumInfo", (num1, num2) => {
      console.log(num1 + num2);
    });
  },
  methods: {
    getMsg(num) {
      console.log(this.msg);
      //触发 分发事件
      this.$emit("getInfo", this.msg, num);
    },
    sum(num1, num2) {
      this.$emit("sumInfo", num1, num2);
    }
  },

  watch: {}
};
</script>
<style lang='' scoped>
</style>